package test8;

import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer, Integer> inMap = new HashMap<>();
        int[] output = new int[n];
        for (int i = 0; i < n; i++) {
            int nextInt = sc.nextInt();
            inMap.put(nextInt, i);
        }
        for (int i = 0; i < n; i++) {
            output[i] = sc.nextInt();
        }
        //改变output数组值
        for (int i = 0; i < output.length; i++) {
            output[i] = inMap.get(output[i]);
        }
        //求出最大递增子序列
        System.out.println(output.length - lengthOfLIS(output));
    }

    public static int lengthOfLIS(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int[] dp = new int[nums.length];
        dp[0] = 1;
        int maxans = 1;
        for (int i = 1; i < nums.length; i++) {
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                }
            }
            maxans = Math.max(maxans, dp[i]);
        }
        return maxans;
    }

}

